package com.lengxf.design;

public class Client {
    private static int index = -1;
    private static final MementoCaretaker mc = new MementoCaretaker();

    public static void main(String[] args) {

        Chessman chessman = new Chessman("车", 1, 1);
        play(chessman);
        chessman.setY(4);

        play(chessman);
        chessman.setX(5);
        play(chessman);

        undo(chessman, index);
        undo(chessman, index);
        redo(chessman, index);
        redo(chessman, index);
    }

    public static void play(Chessman chessman) {
        mc.setChessmanMemento(chessman.save());
        index++;
        System.out.println(chessman);
    }

    public static void undo(Chessman chessman, int i) {
        System.out.println("----悔棋-----");
        index--;
        chessman.restore(mc.getChessmanMemento(i - 1));
        System.out.println(chessman);
    }


    public static void redo(Chessman chessman, int i) {
        System.out.println("---撤销悔棋---");
        index++;
        chessman.restore(mc.getChessmanMemento(i + 1));
        System.out.println(chessman);
    }

}
